<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
</head>
<body>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>导入数据
                    <small></small>
                </h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                           aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#">Settings 1</a>
                            </li>
                            <li><a href="#">Settings 2</a>
                            </li>
                        </ul>
                    </li>
                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <br>
                <div id="demo-form2" class="form-horizontal form-label-left">
                    <input type="hidden" name="id" class="form-data">
                    <input type="hidden" name="buildingId" id="buildingId" class="form-data">
                    <input type="hidden" name="buildingGroupId" id="buildingGroupId" class="form-data">
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="deviceId">设备
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select name="deviceId" id="deviceId" class="form-control form-data">
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="fileDiv">excel
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <button id="uploadBtn" onclick="$('#file_input').click()" class="btn btn-success">上传文件</button>
                            <input type="file" id="file_input" name="file" onchange="uploadFileId('file')" value="Upload your resume"
                                   style="opacity: 0;width: 0px;display: none">
                            <div id="fileDiv" style="padding-top: 23px">

                            </div>
                            <input type="hidden" name="path" value=""/>
                        </div>
                    </div>

                   <!-- <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="fileDiv">excel
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="file" name="file" multiple="true" accept="*/*" id="fileUpload"
                                   style="float:left"
                                   onchange="uploadFile('fileUpload','path', 'fileDiv', 500, '','file')"/>
                            <div id="fileDiv" style="padding-top: 23px;">

                            </div>
                        </div>
                    </div>-->

                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                            <button onclick="back()" class="btn btn-primary" type="button">取消</button>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        setTitle("数据导入>数据导入");
        buildSelectForPage();
    });

    function buildSelectForPage() {
        buildSelect("/admin/device/listAll.do","#deviceId","id","name",{});
    }
    function uploadFileId(fileType) {
        $.ajaxFileUpload({
            url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: fileType+'_input',                        //文件选择框的id属性
            dataType: 'text',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {//服务器成功响应处理函数
                alert("上传成功,正在解析!");
                var rpeObj = $.parseJSON(data);
                var fileInfoList = rpeObj.data;
                $("input[name='path']").val(fileInfoList[0].path);
                save();

            }
        });
    }
    function save() {
        var params = getPageDataByClass("form-data");
        if (strIsNull(params['deviceId'])) {
            alert("请选择设备");
            return;
        }
        params['path'] = $("input[name='path']").val();

        $.ajax({
            url: "/admin/monitorDataImport/import.do",
            data: params,
            async:true,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("解析成功");

                } else {
                    alert("解析出错!"+data.msg);
                }
            }
        });
    }

    function back() {
        goto("house_list.html");
    }
</script>
</html>